<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1"><?php echo $id == 0 ? "新建片段" : "编辑片段" ?></h2>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <strong><?php echo $id == 0 ? "新建片段" : "编辑片段" ?></strong>
                        </div>
                        <div class="card-body">
                            <form class="form-horizontal" role="form" name="form" id="form" method="post"
                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh"
                                  action="index.php?r=admin/fragment/edit" >
                                <input type="hidden" name="id" value="<?php echo $id ?>"/>
                                <input type="hidden" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken; ?>" />

                                <div class="form-group">
                                    <label class=" form-control-label">描述</label>
                                    <input type="text" class="form-control " name="title" value="<?php echo $fragment['title']; ?>" />
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">关键值</label>
                                    <input type="text" class="form-control" name="key" value="<?php echo $fragment['key']==null?"":$fragment['key']; ?>"  />
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">内容</label>
                                    <textarea name="content" style="width:100%;height:300px;">
                            <?php echo $fragment['content']; ?>
                        </textarea>
                                </div>

                                <div class="form-group">
                                    <button  type="submit" name="submit" id="submit" class="btn btn-primary btn-lg btn-block">保存</button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="<?php echo Yii::app()->request->baseUrl ?>/static/admin/lib/kindeditor/kindeditor-min.js"></script>
<script charset="utf-8" src="<?php echo Yii::app()->request->baseUrl ?>/static/admin/lib//kindeditor/lang/zh_CN.js"></script>
<script>
    var editor = null;
    $(function(){
        initPage();
    });
    function initPage() {
        editor = initEdit("content",'fragment')
        $('#form').bootstrapValidator();
        $('#form').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (formData, jqForm, options) {
                return $('#form').data('bootstrapValidator').isValid();
            },
            success: function (res) {
                if (message(res)) {
                    loadContent("index.php?r=admin/fragment/index");
                }
            }
        });
    }
</script>